import 'package:finance_app/src/common/app_colors.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

class CashUtils {
  static String formatCashAmount(num data) {
    if (data == null) return null;
    return NumberFormat('#,##0.00').format(data);
  }

  static String formatDay(num data) {
    if (data == null) return null;
    return NumberFormat('#.#').format(data);
  }

  static bool checkEqual(dynamic data1, dynamic date2) {
    double data1Double = 0.0;
    if (data1 is String) {
      data1Double = double.parse(data1, (e) => 0.0);
    } else if (data1 is num) {
      data1Double = data1.toDouble();
    }

    double data2Double = 0.0;
    if (date2 is String) {
      data2Double = double.parse(date2, (e) => 0.0);
    } else if (date2 is num) {
      data2Double = date2.toDouble();
    }
    return formatCashAmount2(data1Double) == formatCashAmount2(data2Double);
  }

  static String formatCashAmount2(num data) {
    if (data == null) return null;
    return NumberFormat('###0.00').format(data);
  }

  static String formatCashAmountString(String data) {
    if (data == null) return '0.00';
    double value = double.parse(data, (e) => 0.0);
    return formatCashAmount(value);
  }

  static String operation(num amount) {
    return amount == null ? '' : (amount >= 0 ? "+" : "-");
  }

  static String ignoreFormatCashAmount(num amount) {
    if (amount == null) return null;
    num _amount = amount >= 0 ? amount : -amount;
    return formatCashAmount(_amount);
  }

  static String ignoreCashAmount(num amount) {
    if (amount == null) return null;
    num _amount = amount >= 0 ? amount : -amount;
    return _amount.toString();
  }

  static Color getColor(num amount) => amount == null
      ? aceBlackColor
      : (amount >= 0 ? aceGreenColor : aceRedColor);
}
